package cn.itcast.nems.studentrecord.web.controller.b;

import cn.hutool.core.lang.Assert;
import cn.itcast.ic.common.exception.v2.BizExceptionProducer;
import cn.itcast.nems.common.enumeration.NemsErrorBodyEnum;
import cn.itcast.nems.studentrecord.dto.studentrecord.StudentRecordCurrentPaymentDTO;
import cn.itcast.nems.studentrecord.service.studentrecord.StudentRecordPaymentService;
import cn.itcast.nems.studentrecord.web.vo.form.StudentRecordPaymentEditVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/b/student/record/payment")
@Slf4j
@RequiredArgsConstructor
public class StudentRecordPaymentController {

    private final StudentRecordPaymentService studentRecordPaymentService;

    /**
     * 获取分次支付信息
     **/
    @GetMapping("/partial/{studentRecordId}")
    public ResponseEntity<StudentRecordCurrentPaymentDTO> queryPartialPaymentByStudentRecordId(@PathVariable String studentRecordId) {
        return ResponseEntity.ok(studentRecordPaymentService.queryPartialPaymentByStudentRecordId(studentRecordId));
    }

    /**
     * 修改本次支付金额
     *
     * @param requestBody 请求参数
     * @return 分次支付信息
     */
    @PutMapping("/partial/amount")
    public ResponseEntity<StudentRecordCurrentPaymentDTO> modifyPartialPaymentAmount(@RequestBody StudentRecordPaymentEditVO requestBody) {
        Assert.notNull(requestBody, BizExceptionProducer.produce(NemsErrorBodyEnum.PARAM_EMPTY, "请求参数"));
        Assert.notNull(requestBody.getStudentRecordId(), BizExceptionProducer.produce(NemsErrorBodyEnum.PARAM_EMPTY, "请求参数"));
        Assert.notNull(requestBody.getAmount(), BizExceptionProducer.produce(NemsErrorBodyEnum.PARAM_EMPTY, "请求参数"));
        return ResponseEntity.ok(studentRecordPaymentService.modifyPartialPaymentAmount(requestBody.getStudentRecordId(), requestBody.getAmount()));
    }

}
